/**
 *
 * @param color_1
 * @param color_2
 * @param weight
 * @return {string}
 */
const mix = (color_1, color_2, weight) => {
  color_1 = color_1.replace(/#/g , '');
  color_2 = color_2.replace(/#/g , '');

  function d2h(d) {
    return d.toString(16);
  }

  function h2d(h) {
    return parseInt(h, 16);
  }

  weight = weight || 50;

  let color = "#";

  for (let i = 0; i <= 5; i += 2) {
    let v1 = h2d(color_1.substr(i, 2)), v2 = h2d(color_2.substr(i, 2)), val = d2h(Math.floor(v2 + (v1 - v2) * (weight / 100.0)));

    while (val.length < 2) {
      val = '0' + val;
    }

    color += val;
  }

  return color;
};

export { mix }
